<?php

class Common_Dialog extends GtkDialog
{
    function __construct($args)
    {
        parent::__construct($args["title"], null, Gtk::DIALOG_MODAL);
        $buttons = explode("|", $args["buttons"]);
        foreach($buttons as $button) {
            $itens[$button] = 1;
        }
        
        if (isset($itens["yes"])) {
            $this->add_button(Gtk::STOCK_YES, 1);
        }
        
        if (isset($itens["no"])) {
            $this->add_button(Gtk::STOCK_NO, 2);
        }
                    
        if (isset($itens["cancel"])) {
            $this->add_button(Gtk::STOCK_CANCEL, 3);
        }
        
        if (isset($itens["ok"])) {
            $this->add_button(Gtk::STOCK_OK, 4);
        }
        
        /* Creating and adding a question to the dialog */
        $dialogQues = new GtkLabel($args["message"]);
        $topArea = $this->vbox;
        $topArea->add($dialogQues);
    }
    
    function getResponse()
    {
        /* Showing all widgets added */
        $this->show_all();

        /* Running the dialog box */
        $result = $this->run();

        /* Accessing the result and performing
           appropriate action */
        switch($result) {
            case (1):
                $answer = "yes";
                break;
            case (2):
                $answer = "no";
                break;
            case (3);
                $answer = "cancel";
                break;
            case (4);
                $answer = "ok";
                break;
        }
        
        /* Destroying the dialog box */
        $this->destroy();
        return($answer);
        
    }
}

